package com.ic.service.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ic.domain.Device;
import com.ic.service.DeviceService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DeviceServiceImpl implements DeviceService {
    private Map<String, Device> deviceMap = Maps.newConcurrentMap();

    @Override
    public void save(Device device) {
        deviceMap.put(device.getId(), device);
    }

    @Override
    public Device findById(String id) {
        return deviceMap.get(id);
    }

    @Override
    public List<Device> findAll() {
        return Lists.newArrayList(deviceMap.values());
    }

    @Override
    public Device delete(String id) {
        return deviceMap.remove(id);
    }
}
